package com.oscar.web.controller;

import com.oscar.web.domain.Book;
import com.oscar.web.domain.RateMoreBooks;
import com.oscar.web.domain.RateMoreRecentlyBooks;
import com.oscar.web.service.RecommenderService;
import com.oscar.web.service.UserBookCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.sql.DataSource;
import java.util.List;

@Controller
public class IndexController {

    @Autowired
    private DataSource dataSource ;

    @Autowired
    private RecommenderService recommenderService;






    //获取历史热门推荐
    @RequestMapping("/books/hot")
    public ModelAndView getHotBooks(Integer pageNumber){
        ModelAndView mv = new ModelAndView("hot") ;
        if(pageNumber == null)pageNumber = 0 ;
        List<Book> list = recommenderService.getHistoryHotRecommendations(pageNumber);
        Page<RateMoreBooks> page = recommenderService.getHistoryHot(pageNumber);

        mv.addObject("list",list);
        mv.addObject("page",page);
        return mv;
    }

    //注册页面
    @RequestMapping("/register")
    public ModelAndView toRegister() {
        ModelAndView mv = new ModelAndView("register") ;
        return mv;
    }
    //登录页面
    @RequestMapping("/mylogin")
    public ModelAndView toLogin() {
        ModelAndView mv = new ModelAndView("login") ;
        return mv;
    }

}
